<?php

namespace App\Enums;

use App\Util\ArrayHelper;

abstract class BaseEnums
{

    const SYSTEM_ERR = -1;
    const FORBIDDEN = 403;
    const NOT_FOUND = 404;
    const REQUEST_METHOD_ERR = 405;
    const DUPLICATE = 406;
    const SYSTEM_EXCEPTION = 500;

    const NO_LOGIN = 1001;
    const NO_GRANT = 1002;
    const NO_MOBILE = 1003;
    const EXISTS_MOBILE = 1004;

    /**
     * 错误码与描述的映射关系，以K=>V数组返回
     * @return array
     */
    abstract protected static function codesMap() : array;

    protected static function baseMap() : array
    {
        return [
            self::SYSTEM_ERR         => '系统错误',
            self::FORBIDDEN          => '没有访问权限',
            self::NOT_FOUND          => '页面不存在',
            self::REQUEST_METHOD_ERR => '请求方式错误',
            self::DUPLICATE          => '重复请求错误',
            self::SYSTEM_EXCEPTION   => '系统异常',
            self::NO_LOGIN           => '请登陆',
            self::NO_GRANT           => '请授权获取信息',
            self::NO_MOBILE          => '请授权手机号',
            self::EXISTS_MOBILE          => '该手机号码已经注册！',
        ];
    }

    public static function get($key) : string
    {
        $array = ArrayHelper::merge(self::baseMap(), static::codesMap());
        return ArrayHelper::getValue($array, $key, '系统繁忙！');
    }

}
